<template>
  <div>
    <!-- 新增修改表单 -->
    <el-dialog :title="textMap[dialogStatus]+'('+parentNodeName+')'" :visible.sync="DialogFormVisibleCom">
      <el-form ref="dataForm" :model="formSubmitDataCom" :rules="rules" label-position="right" label-width="100px"
               style="width: 90%; margin:10px auto;">

        <el-row :gutter="20">
          <el-col :span="12">
            <!-- 机构编号 -->
            <el-form-item label="产品编号：" prop="prod_code">
              <el-input v-model="formSubmitDataCom.prod_code" v-bind:disabled='formSubmitData.id!=""'/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 机构名称 -->
            <el-form-item label="产品名称：" prop="prod_name">
              <el-input v-model="formSubmitDataCom.prod_name"/>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <!-- 备注 -->
            <el-form-item label="备注：" prop="remark">
              <el-input v-model="formSubmitDataCom.remark" placeholder="" type="textarea"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="dialogStatusClick">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// import PageHeaderLayout from '@/layouts/PageHeaderLayout'
// import ApeDrawer from '@/components/ApeDrawer'
// import { mapGetters } from 'vuex'

export default {
  name: 'submitForm',
  components: {
    //PageHeaderLayout,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    dialogStatus: {
      type: String,
    },
    parentNodeName: {
      type: String,
    },

    formSubmitData: {
      type: Object,
      default: function () {
        return {
          id: '',
          branch_abd: '',
          branch_code: '',
          branch_flag: '',
          branch_name: '',
          branchlevel: '',
          lp_code: '',
          ord_num: 0,
          parent_branch_id: '',
          remark: '',
          rg_date: '',
          status: "",
          te_date: '',
        }
      }
    }
  },
  // 定义属性
  data() {
    return {
      textMap: {
        update: '修改',
        create: '新增一级机构',
        addSonNode: '新增子机构',
      },
      rules: {
        prod_code: [{required: true, message: '产品编号必填', trigger: 'change'}],
        prod_name: [{required: true, message: '产品名称必填', trigger: 'change'}],
      },
    
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    }
  },
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    // 重置
    resetFormData() {
      this.$emit('resetFormDataEmit')
    },
    dialogStatusClick() {
      //  dialogStatus==='create'?createData():updateData()
      if (this.dialogStatus === 'create') {
        this.createData()
      } else if (this.dialogStatus === 'update') {
        this.updateData()
      } else {
        this.addSonNode()
      }
    },

    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromCreateDataEmit')

        }
      })
    },

    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$delete(this.formSubmitData, "lp_name");
          // const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromUpdateDataEmit')
        }
      })
    },
    addSonNode() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          // const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromAddSonNodeEmit')
        }
      })
    }

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>

</style>